package model

import (
	"time"
	"user_srv/basic/config"
)

// 好友动态表
type XqFriendActivities struct {
	Id        int64     `gorm:"column:id;type:bigint;primaryKey;not null;" json:"id"`
	UserId    int64     `gorm:"column:user_id;type:bigint;not null;index;comment:发布者用户ID;" json:"user_id"`
	Content   string    `gorm:"column:content;type:text;comment:动态文本内容;" json:"content"`
	Images    string    `gorm:"column:images;type:json;comment:图片URL JSON数组;" json:"images"`
	CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
}

func (x *XqFriendActivities) TableName() string { return "xq_friend_activities" }

func (x *XqFriendActivities) Create() error { return config.DB.Create(&x).Error }

func (x *XqFriendActivities) ListByUserIds(userIds []int64, limit, offset int) ([]XqFriendActivities, error) {
	var list []XqFriendActivities
	if len(userIds) == 0 {
		return list, nil
	}
	q := config.DB.Where("user_id IN (?)", userIds).Order("id DESC")
	if limit > 0 {
		q = q.Limit(limit)
	}
	if offset > 0 {
		q = q.Offset(offset)
	}
	err := q.Find(&list).Error
	return list, err
}
